/**
 * 
 */
var BSTMG = BSTMG || {};
BSTMG.goodpublish = {
	init: function(){
		var that = this;
		/* 初始化选项卡 */
		BSTMG.plugins.prettyTab();
		that.initTabs();
		/* 初始化编辑器 */
		that.initKindEditors();
		/* 裁剪商品图标 */
		that.jcropProIcon();
		/* 确认发布 */
		that.submitForm();
		/* 选择分类产品 */
		that.chooseCategoryProducts()
	},
	initTabs: function(){
		$(".prettyTab").prettyTab({
            current: 0,
            currentClass: 'on'
        });
	},
	initKindEditors: function(){
		var options = {
			width: "100%",
        	height: "300px",
			cssPath : '/cdn/kindeditor-4.1.10/plugins/code/prettify.css',
			uploadJson : '/cdn/kindeditor-4.1.10/jsp/upload_json.jsp?objectName=product',
			fileManagerJson : '/cdn/kindeditor-4.1.10/jsp/file_manager_json.jsp',
			allowFileManager : false,
			afterCreate : function() {
				var self = this;
				KindEditor.ctrl(document, 13, function() {
					self.sync();
					document.forms['example'].submit();
				});
				KindEditor.ctrl(self.edit.doc, 13, function() {
					self.sync();
					document.forms['example'].submit();
				});
			}
		};
		var editors = ["pro_goverview","pro_funcintro","pro_advantage","pro_charge","pro_download","pro_abstract"];
		KindEditor.ready(function(K) {
			$.each(editors,function(index,val){
				window[val] = K.create( '#' + val , options );
			});
		});
		
	},
	jcropProIcon: function(){
		var that = this,
			$filehidden = $("#advImage"),
			$picurl = $('#picUrl'),
			$cutbox = $(".iconcutbox"),
			$target = $("#showImg"),
			$previewpane = $("#preview-pane"),
			$previewimg = $("#crop_preview");
		var $proalbum = $(".proalbum"),
			$iconpreview = $("#iconpreview");
		var kong = "/images/admin/kong.gif" ;
		var jQcrop = {			// 裁剪对象 全局
				obj: null,
				width: null,
				height: null
		};
		// 裁剪图片模块
		var JCROP = {
				init: function(){
					var panelwidth = $previewpane.width(),
						panelheight = $previewpane.height();
					// 图片上传
					$cutbox.on("change","#advImage",function(){
						// 检查图片格式
						var f = $filehidden.val();
						if(!/.(gif|jpg|jpeg|png|JPG|PNG)$/.test(f)) {
						    BSTYUN.dialog.warn("图片类型必须是.jpeg,jpg,png中的一种");
						    return false;
						}
						$.ajaxFileUpload({
							url:"/uploadFile/image?attachType=2&objectName=product",
							secureuri:false,
							fileElementId:"advImage",
							dataType:"json",
							success:function(data) {
								if(data.message == "上传文件成功") {
									var path = data.path;
									$picurl.val( path );
									$('#attachIds').val(data.attachId);
									try{
										var original_img = new Image();
										original_img.src = path ;
										original_img.onload = function(){
											jQcrop.width = this.width;
											jQcrop.height = this.height;
										};
										$previewimg.attr('src', path );
										$target.load(function(){
											reJcropImg();
										}).attr('src', path );
									}catch(e){
										if( window.console ) {
											console.warn("图片裁剪插件初始化失败！");
										}
									}
								}else{
									BSTYUN.dialog.warn(data.message);						
								}
							},
							error:function (data, status, e) {
								BSTYUN.dialog.warn("图片上传失败,请重新选择图片！");
							}
						});
					});
					// 重新初始化裁剪
					function reJcropImg(){
						if( !!jQcrop.obj ) {
							jQcrop.obj.destroy();
							jQcrop.obj = null;
						}
						$target.Jcrop({
							onChange:showPreview,
							onSelect:showPreview // aspectRatio: 1
						},function(){
							jQcrop.obj = this;
						});
						function showPreview(coords){			
							if( parseInt(coords.w) > 0 ){
								//计算预览区域图片缩放的比例，通过计算显示区域的宽度(与高度)与剪裁的宽度(与高度)之比得到
								var rx = panelwidth / coords.w; 
								var ry = panelheight / coords.h;
								//通过比例值控制图片的样式与显示
								$previewimg.css({
									width:Math.round( rx * $target.width() ) + "px",		//预览图片宽度为计算比例值与原图片宽度的乘积
									height:Math.round( ry * $target.height() ) + "px",		//预览图片高度为计算比例值与原图片高度的乘积
									marginLeft:"-" + Math.round( rx * coords.x ) + "px",
									marginTop:"-" + Math.round( ry * coords.y ) + "px"
								});
							};
						};
					};
					// 确认裁剪
					$cutbox.on("click",".confirmcut",function(){
						if( !!!jQcrop.obj ) {
							BSTYUN.dialog.warn("请上传一张图片裁剪！");
							return false;
						};
						var url = $picurl.val();
						var scale = jQcrop.obj.tellSelect(), //裁剪的尺寸
							bound = jQcrop.obj.getBounds();		// 获取图片实际尺寸，格式为：[w, h]
						var rx = jQcrop.width / bound[0] ,
							ry = jQcrop.height / bound[1] ;
						var scaledata = {
								w: scale.w * rx ,
								h: scale.h * ry ,
								x: scale.x * rx ,
								y: scale.y * ry ,
								x2: scale.x2 * rx ,
								y2: scale.y2 * ry ,
								url: url,
								attachType: 2
						}
						var temple = null;
						for( var key in scaledata ){
							temple = scaledata[ key ];
							scaledata[ key ] = isNaN( temple ) ? temple : parseInt( scaledata[ key ] );
						};
						//scale数据格式类似于：{w: 134 ,h: 134 , x: 91 , y: 74 , x2: 225 , y2: 208} w宽度，h高度，x，y左上角坐标，x2，y2右下角坐标
						if( scaledata.w == 0 && scaledata.h == 0 ) {
							// 没有裁剪，直接原图保存
							if( !!jQcrop.obj ) {
								jQcrop.obj.destroy();
								jQcrop.obj = null;
							};
							$previewimg.attr("src", url ).css({
								width: 100,
								height: 100,
								marginLeft: 0,
								marginTop: 0
							});
							BSTYUN.dialog.ok("图片上传成功！");
							return false;
						};
						$.ajax({
							type: 'post',
							url: "/sysAdmin/operate/goodsListAdmin/cutImg",
							data: scaledata ,
							dataType: 'json',
							beforeSend: null,
							complete: null,
							success: function(data){
								var url = data.saveUrl ;
								$('#attachIds').val(data.attachId);
								if( !!jQcrop.obj ) {
									jQcrop.obj.destroy();
									jQcrop.obj = null;
								}
								$picurl.val( url );
								$previewimg.attr("src", url ).css({
									width: 100,
									height: 100,
									marginLeft: 0,
									marginTop: 0
								});
								$target.off().attr("src", url );
								// 清空产品相册的选择
								ALBUM.destory();
								BSTYUN.dialog.ok("图片上传成功！");
							},
							error: function(){
								BSTYUN.dialog.warn("图片上传失败，请检查网络！");
							}
						});
					});
				},
				destory: function(){
					if( !!jQcrop.obj ) {
						jQcrop.obj.destroy();
						jQcrop.obj = null;
					}
					$target.attr( "src" , kong );
					$previewimg.attr( "src" , kong );
				}
		};
		// 产品相册对象
		var ALBUM = {
				initChooseIcon: function(){
					// 选择产品图片
					$proalbum.find(".row").on("click",".proimgbox",function(){
						var $this = $(this),
							$icon = $this.find(".proimg"),
							$fa = $this.find("i.fa");
						if ( $fa.length ) {
							$fa.show();
						}else{
							$this.append('<i class="fa fa-fw fa-check-circle-o"></i>');
						}
						$this.siblings("div").find("i.fa").hide();
						$iconpreview.attr("src", $icon.attr("src") );
					});
					// 点击确认保存
					$proalbum.find(".confirmsave").on("click",function(){
						var $fa = $proalbum.find("div.proimgbox .fa").not(":hidden");
						if( $fa.length ) {
							var src = $iconpreview.attr("src");
							$picurl.val( src );
							BSTYUN.dialog.ok("图片保存成功！");
							// 清空裁剪图片
							JCROP.destory();
						}else{
							BSTYUN.dialog.warn("请从产品相册中选择一张图片！");
						};
					});
				},
				destory: function(){
					// 清空选择
					$proalbum.find("i.fa").hide();
					$iconpreview.attr("src", kong );
				}
		}
		// 初始化裁剪对象
		JCROP.init();

		// 初始化产品相册选择
		ALBUM.initChooseIcon();
	},
	submitForm: function(){
		var $buttons = $(".publishbutton"),
			$form = $("#sec2").find(".form-group");
		var editors = ["pro_goverview","pro_funcintro","pro_advantage","pro_charge","pro_download","pro_abstract"];
		// 输入框组
		var $good = $("#good"),
			$inputs = $good.find("input"),
			$selects = $good.find("select");
		var jqobj = {
			// 各种input
			$goodsNum : $inputs.filter("[name=goodsNum]"),
			$goodsName : $inputs.filter("[name=goodsName]"),
			$goodsUrl : $inputs.filter("[name=goodsUrl]"),
			$goodsImgUrl : $inputs.filter("[name=goodsImgUrl]"),
			$goodsDeveloper : $inputs.filter("[name=goodsDeveloper]"),
			$goodsVersion : $inputs.filter("[name=goodsVersion]"),
			$usersMin : $inputs.filter("[name=usersMin]"),
			$usersMax : $inputs.filter("[name=usersMax]"),
			$yearsMin : $inputs.filter("[name=yearsMin]"),
			$yearsMax : $inputs.filter("[name=yearsMax]"),
			$goodsPrice : $inputs.filter("[name=goodsPrice]"),
			$privilege : $inputs.filter("[name=privilege]"),
			
			$categoryproes: $inputs.filter("[name=categoryproes]"),
			$goodsRalateGoods: $selects.filter("[name=goodsRalateGoods]"),
			
			// 各种select
			$typeId : $selects.filter("[name=typeId]"),
			$industryCode : $selects.filter("[name=industryCode]"),
			$categoryCode : $selects.filter("[name=categoryCode]"),
			$goodsPriceUnit : $selects.filter("[name=goodsPriceUnit]"),
			$goodsFeeId : $selects.filter("[name=goodsFeeId]"),
			// 各种textarea
			$pro_character : $("#pro_character"),
			$pro_abstract : $("#pro_abstract"),
			$pro_goverview : $("#pro_goverview"),
			$pro_funcintro : $("#pro_funcintro"),
			$pro_advantage : $("#pro_advantage"),
			$pro_charge : $("#pro_charge"),
			$pro_download : $("#pro_download"),
			$pro_remark : $("#pro_remark")
		};
		var fieldmsg = {
			// 各种input
			$goodsNum : "商品编码",
			$goodsName : "商品名称",
			$goodsUrl : "商品URL",
			$goodsImgUrl : "商品图标",
			$goodsDeveloper : "软件开发商",
			$goodsVersion : "版本编号",
			$usersMin : "用户数范围低位段",
			$usersMax : "用户数范围高位段",
			$yearsMin : "年限范围低位段",
			$yearsMax : "年限范围高位段",
			$goodsPrice : "报价",
			$privilege : "优惠折扣",
			
			$categoryproes: "选择分类产品",
			$goodsRalateGoods: "关联商品",
			
			// 各种select
			$typeId : "商品分类",
			$industryCode : "行业",
			$categoryCode : "应用类别",
			$goodsPriceUnit : "报价单位",
			$goodsFeeId : "计费模式",
			// 各种textarea
			$pro_character : "商品简介",
			$pro_abstract : "简短描述",
			$pro_goverview : "功能概述",
			$pro_funcintro : "功能介绍",
			$pro_advantage : "产品优点",
			$pro_charge : "收费标准",
			$pro_download : "下载中心",
			$pro_remark : "备注"
		};
		var errormsg = {
			// 各种input
			$goodsNum : null,
			$goodsName : null,
			$goodsUrl : null,
			$goodsImgUrl : null,
			$goodsDeveloper : null,
			$goodsVersion : null,
			$usersMin : null,
			$usersMax : null,
			$yearsMin : null,
			$yearsMax : null,
			$goodsPrice : null,
			$privilege : null,
			
			$categoryproes: null,
			$goodsRalateGoods: null,
			
			// 各种select
			$typeId : null,
			$industryCode : null,
			$categoryCode : null,
			$goodsPriceUnit : null,
			$goodsFeeId : null,
			// 各种textarea
			$pro_character : null,
			$pro_abstract : null,
			$pro_goverview : null,
			$pro_funcintro : null,
			$pro_advantage : null,
			$pro_charge : null,
			$pro_download : null,
			$pro_remark : null
		};
		// 初始化表单对象
		var objForm = {
			// 获取表单数据
			getData: function(){
				var data = {};
				$.each(editors,function(index,val){
					window[val].sync();
				});
				for( var key in jqobj ){
					data[key] = $.trim( jqobj[key].val() );
				};
				data["categoryproes_ids"] = $.trim( jqobj["$categoryproes"].attr("data-ids") );
				return data ;
			},
			// 检验数据合法性
			checkValidity: function( values ){
				var data = values ;
				var kong = [ "$goodsUrl", "$privilege", "$pro_remark" , "$goodsRalateGoods" ];
				for( var key in data ) {
					if( data[key] == "" && kong.indexOf( key ) < 0 ){ //排除可以为空的情况
						BSTYUN.dialog.warn( fieldmsg[key] + "不能为空!" );
						return false;
					};
					// 触发事件
					if( jqobj[key] ){
						var events = $._data( jqobj[key][0], "events");
						if ( events  ){
							for(var event in events ){
								event == "blur" ? jqobj[key].trigger( event ) : '' ;
							};
						};
					};
					if( errormsg[key] ){
						if( window.console ){
							console.warn( errormsg[key] );
						};
						return false;
					};
				};
				return true;
			}
		};
		// 商品编码 数据合法性校验
		jqobj["$goodsNum"].on("blur",function(){
			var $this = $(this),
				value = $.trim( $this.val() );
			// 1-1000的整数
			if( isNaN(value) || value.indexOf(".") >= 0 ){
				errormsg["$goodsNum"] = "请输入正确格式的商品编码！";
				BSTYUN.dialog.warn( errormsg["$goodsNum"] );
				return false;
			};
			value = Number( value );
			if( value < 1 || value > 1000 ){
				errormsg["$goodsNum"] = "请输入正确格式的商品编码！";
				BSTYUN.dialog.warn( errormsg["$goodsNum"] );
				return false;
			};
			errormsg["$goodsNum"] = null;
		});
		
		// 用户数范围 数据合法性校验
		jqobj["$usersMin"].on("blur",function(){
			var $this = $(this),
				min = $.trim( $this.val() ),
				max = $.trim( $this.nextAll("[name=usersMax]").val() ) ;
			compareTwoNumber( min , max , 0 )
		});
		jqobj["$usersMax"].on("blur",function(){
			var $this = $(this),
				max = $.trim( $this.val() ),
				min = $.trim( $this.prevAll("[name=usersMin]").val() ) ;
			compareTwoNumber( min , max , 0 )
		});
		// 年限范围 数据合法性校验
		jqobj["$yearsMin"].on("blur",function(){
			var $this = $(this),
				min = $.trim( $this.val() ),
				max = $.trim( $this.nextAll("[name=yearsMax]").val() ) ;
			compareTwoNumber( min , max , 1 );
		});
		jqobj["$yearsMax"].on("blur",function(){
			var $this = $(this),
				max = $.trim( $this.val() ),
				min = $.trim( $this.prevAll("[name=yearsMin]").val() ) ;
			compareTwoNumber( min , max , 1 );
		});
		function compareTwoNumber( min , max , flag ){
			var error = flag == 0 ? "用户数" : "年限数" ;
			if( isNaN( min ) || min.indexOf(".") >= 0 || /^-/.test( min ) ) {
				error = "请输入正确的低位段" + error + "!" ;
				BSTYUN.dialog.warn( error ) ;
				flag == 0 ? errormsg["$usersMin"] = error :
							errormsg["$yearsMin"] = error;
				return false;
			};
			if( isNaN( max ) || max.indexOf(".") >= 0 || /^-/.test( max )  ) {
				error = "请输入正确的高位段" + error + "!" ;
				BSTYUN.dialog.warn( error ) ;
				flag == 0 ? errormsg["$usersMax"] = error :
							errormsg["$yearsMax"] = error;
				return false;
			};
			if( !!min && !!max ){
				min = Number( min );
				max = Number( max );
				if( min >= max ){
					error = "低位段不能大于等于高位段" + error + "!" ;
					BSTYUN.dialog.warn( error ) ;
					flag == 0 ? errormsg["$usersMin"] = error :
								errormsg["$yearsMin"] = error;
					return false;
				};
			};
			if( flag == 0 ){
				errormsg["$usersMin"] = null ;
				errormsg["$usersMax"] = null ;
			}else{
				errormsg["$yearsMin"] = null ;
				errormsg["$yearsMax"] = null ;
			};
		};
		// 报价 验证数据合法性
		jqobj["$goodsPrice"].on("blur",function(){
			var $this = $(this),
				price = $.trim( $this.val() );
			// 1-1000的整数
			if( isNaN( price ) ){
				errormsg["$goodsPrice"] = "请输入正确格式的报价！";
				BSTYUN.dialog.warn( errormsg["$goodsPrice"] );
				return false;
			};
			price = price == "" ? price : Number( price );
			$this.val( price );
			errormsg["$goodsPrice"] = null;
		});
		// 优惠折扣 验证数据合法性
		jqobj["$privilege"].on("blur",function(){
			var $this = $(this),
				discount = $.trim( $this.val() );
			if( isNaN( discount )){
				errormsg["$privilege"] = "请输入正确格式的优惠折扣！";
				BSTYUN.dialog.warn( errormsg["$privilege"] );
				return false;
			}else if(discount<0||discount>1){
				errormsg["$privilege"] = "请输入0-1范围内的优惠折扣！";
				BSTYUN.dialog.warn( errormsg["$privilege"] );
				return false;
			};
			discount = discount == "" ? discount : Number( discount );
			$this.val( discount );
			errormsg["$privilege"] = null;
		});
		// 发布预览 保存至未提交 申请发布
		$buttons.on("click",".confirmpublish",function(){
			var data = objForm.getData();
			if( objForm.checkValidity( data ) ){	// 检验正确
				BSTMG.goodpublish.addGood( 1 , data );
			};
			// 保存至未提交
		}).on("click",".unApply",function(){
			var data = objForm.getData();
			if( objForm.checkValidity( data ) ){	// 检验正确
				BSTMG.goodpublish.addGood( 0 , data );
			};
		}).on("click",".preview",function(){
			//发布预览
			var data = objForm.getData();
			if( objForm.checkValidity( data ) ){	// 检验正确
				BSTMG.goodpublish.addGood( 1 , data );
			};
		});
	},
	//保存商品发布信息
	addGood : function( auditState , data ) {
		var editors = ["pro_goverview","pro_funcintro","pro_advantage","pro_charge","pro_download","pro_abstract"];
		$.each(editors,function(index,val){
			window[val].sync();
		});
		//表单对象序列化
		var datas = $('.form-horizontal').serialize();
		datas +="&categoryproes_ids=" + data["categoryproes_ids"];
		$.ajax({
			type: 'POST',
			url: "/sysAdmin/operate/goodsListAdmin/addGoods?auditState="+auditState,
			data: datas,
			dataType: 'json',
			success: function(data){
				if(data.isSuccess) {
					location.href="/sysAdmin/goodsListAdmin/goodsList";
				}else {
					BSTYUN.dialog.warn("商品信息保存失败，请重新保存！");
				}
			},
			error: function(){
				BSTYUN.dialog.warn("网络异常，请检查网络！");
			}
		});
	},
	/*选择产品*/
	chooseCategoryProducts: function(){
		var that = this,
			$selectors = $("#chooseCategoryProducts");
		
		$selectors.on("click",".input-group-addon",function(){
			var $input = $(this).prev();
			showCategory.call( $input );
		}).on("click","input.form-control",function(){
			showCategory.call( $(this) );
		}).on("keydown","input.form-control",function(){
			return false;
		});
		
		function showCategory(){
			var $input = this,
				getnewcallback = $.Callbacks();
			var dialog = null;
			var html = '<div id="chooseproduct"><table class="table table-bordered chopdtable"><thead><tr><th><label class="icheck checkall"><input type="checkbox" class="simple"> <span>全选</span></label></th><th>序号</th><th><span class="filter filterno">产品编码</span></th><th><span class="filter filtername">产品名称</span></th></tr></thead><tbody></tbody></table></div>';
			dialog = BSTYUN.dialog.creat({
				id : "categories",
				title: "选择产品",
				content : html,
				top: "58px",
				init: initChooseProducts
			});
			dialog.button(
				{
					name : "获取最新产品列表",
					callback : getNewlyProducts
				},
				{
					name : "确定",
					callback : getConfirmResult
				},{
					name : "取消"
				}
			);
			// 初始化对话框
			function initChooseProducts(){
				var $content = this.DOM.content,
					$thead = $content.find("thead"),
					$tbody = $content.find("tbody");
				// 全选
				$thead.on("click",".checkall",function(){
					var $this = $(this),
						$current = $this.find(".simple"),
						$parent = $this.parents('table.chopdtable'),
						$checkbox = $parent.find('input[type=checkbox]').not($current);
					$current.prop("checked") ? $checkbox.prop("checked",true) : $checkbox.prop("checked",false) ;
				});
				$tbody.on("click","input[type=checkbox]",function(){
					var $this = $(this),
						$all = $this.parents("tbody").eq(0).find("input[type=checkbox]"),
						$checkbox = $all.not($this).filter(":checked");
					var $checkall = $thead.find(".checkall input[type=checkbox]");
					( $this.prop("checked") && ($checkbox.length + 1) == $all.length ) ? $checkall.prop("checked",true) : $checkall.prop("checked",false) ;
				});
				// 获取最新列表
				getnewcallback.add( appenDataToTable );
				// 将ajax获取的数据放入tbody
				function appenDataToTable( data ){
					if(data.isOk){
						var goodsList = data.goodsList;
						var html = '';
						for(var i=0;i<goodsList.length;i++){
							var goods = goodsList[i];
							html += '<tr><td><input type="checkbox" class="simple" ></td>';
							html += '<td>'+(i+1)+'</td>';
							html += '<td class="pronum">'+goods.goodsNum+'</td>';
							html += '<td class="proname">'+goods.goodsName+'</td></tr>';
						};
						$tbody.html(html);
						checkSelectedPro();
					}else{
						var $tr = '<tr><td colspan="3"> 查无数据！请添加分类！</td></tr>';
		                $tbody.html($tr);
					};
				};
				// 初始化选中产品
				function checkSelectedPro(){
					var products = $.trim( $input.attr("data-ids") );
					if( !!!products ) { return false ;}
					$.each(products.split(","),function(index,value){
						$tbody.find("td.pronum").each(function(sub,va){
							
							var $this = $(this);
							if( value == $.trim( $(this).text() ) ) {
								$this.parent().find("input[type=checkbox]").prop("checked",true);
							};
						});
					});
					var $all = $tbody.find("input[type=checkbox]"),
						$checked = $all.filter(":checked"),
						$checkall = $thead.find(".checkall input[type=checkbox]");
					$all.length == $checked.length ? $checkall.prop("checked",true) : $checkall.prop("checked",false) ;
				};
				// 默认获取最新产品
				getNewlyProducts.apply( this );
			};
			// 获取最新产品列表
			function getNewlyProducts(){
				var $content = this.DOM.content,
					$thead = $content.find("thead"),
					$tbody = $content.find("tbody"),
					loading = null;
				//获取最新产品列表
				$.ajax({
					url: '/sysAdmin/goodsListAdmin/selectProductByPortal',
					type: 'post',
					dataType: 'json',
					beforeSend: function(){
						$content.css( {"background": "url(/images/admin/loading_normal.gif) no-repeat center"});
					},
					complete: function(){
						$content.css( {"background": "none"});
					},
					success: function(data){
						getnewcallback.fire( data );
					},
					error: function(){
						BSTYUN.dialog.warn("网络错误，请稍后重试！",function(){
							BSTYUN.dialog.close()
						});
					}
				});
				return false;
			};
			// 确定分类产品，写入input
			function getConfirmResult(){
				var $content = this.DOM.content,
					$thead = $content.find("thead"),
					$tbody = $content.find("tbody");
				var $checkbox = $tbody.find("input.simple:checked");
				var result = [],
					resultid = [];
				$checkbox.each(function(index,val){
					var $this = $(this),
						$tr = $this.parent().parent(),
						txt = $.trim( $tr.find(".proname").text() ),
						id = $.trim( $tr.find(".pronum").text() );
					result.push(txt);
					resultid.push(id);
				});
				
				// 获取产品的值和id
				$input.val( result.join(",") ).attr("data-ids",resultid.join(","));
			};
		};// showCategory 结束
	}
};

$(function(){
	BSTMG.goodpublish.init();
});
